package com.auto.reg.web;

import java.util.Timer;
import java.util.TimerTask;

import com.auto.reg.util.CmdUtil;
import com.auto.reg.util.RefreshRegInfoUtil;
import com.auto.reg.util.RegConstant;

public class WebRegManager {
	
	public static void main(String[] args) {
		Timer timer = new Timer(false);
		WorkerTask task = new WebRegManager().new WorkerTask("web_reg.exe");
		FileMonitor.addFileListener(RegConstant.FIRE_FOX_DIR);
		timer.scheduleAtFixedRate(task, 0, 6000);
	}

    class WorkerTask extends TimerTask {
		
		private String processName;
		
		public WorkerTask(String processName) {
			this.processName = processName;	 				
		}

		@Override
		public void run() {
            if (CmdUtil.findProcess("auto_save.exe") == false && CmdUtil.findProcess(processName) == false) {
            		 				
            	try {
            		RefreshRegInfoUtil.refreshIni();
            		CmdUtil.openUrlInExplore("https://appleid.apple.com/cgi-bin/WebObjects/MyAppleId.woa/wa/createAppleId?localang=zh_CN");
					Thread.sleep(6000);
					
					if (CmdUtil.findProcess("firefox.exe")) {
						CmdUtil.executeCommand("auto_res/auto_save.exe");
					}
				} catch (RuntimeException re) {
					re.printStackTrace();
					CmdUtil.executeCommand("tskill iexplore");
					return;
				} catch (Exception e) {
					e.printStackTrace();
				    return;
				}
            }
		}
	}
}